package com.dmcb.common.web.conversion;

import java.io.Serializable;

/**
 * Created by a on 2015/3/11.
 */
public class JsonResult implements Serializable {

    private static final long serialVersionUID = 7934763623184866074L;
    /**
     * 请求有错误提示
     */
    public static final int STATUS_ERROR = 0;
    /**
     * 请求成功
     */
    public static final int STATUS_SUCCESS = 1;

    /**
     * 请求警告
     */
    public static final int STATUS_WARN = 2;

    private int status = 1;
    private String msg;
    private Object data;
    private Object key;
    private String href;

    public boolean isSuccess() {
        return status == STATUS_SUCCESS;
    }

    public boolean isWarn() {
        return status == STATUS_WARN;
    }

    public boolean isError() {
        return status == STATUS_ERROR;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public int getInt() {
        if (data != null && data instanceof Integer)
            return (Integer) data;
        return 0;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Object getKey() {
        return key;
    }

    public void setKey(Object key) {
        this.key = key;
    }

    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href;
    }

    @Override
    public String toString() {
        return "JsonResult{" +
                "status=" + status +
                ", msg='" + msg + '\'' +
                ", data=" + data +
                ", key=" + key +
                ", href='" + href + '\'' +
                '}';
    }
}
